const fs = require('fs');
const path = require('path');
function totalFileSizeSync(fileSrc = '', size = 0) {
    const stat = fs.statSync(path.resolve(fileSrc))
    if (stat.isDirectory()) {
        const paths = fs.readdirSync(path.resolve(fileSrc))
        for (let i = 0; i < paths.length; i++) {
            const statDeep = fs.statSync(paths[i])
            if (statDeep.isDirectory()) {
                return totalFileSize(path.resolve(paths[i]), size)
            }
            if (statDeep.isFile()) {
                size += statDeep.size
                return size
            }
            return statDeep.size
        }
    } else {
        return size
    }
}
console.log(totalFileSizeSync('../code'))